/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.service;

import br.siagefi.dao.DAO;
import br.siagefi.model.Documento;
import br.siagefi.model.TipoNotaFiscal;
import java.util.List;

/**
 *
 * @author Paulo Lavarini
 */
public class TipoNotaFiscalService {
     private final DAO<TipoNotaFiscal> dao;

    public TipoNotaFiscalService() {
        this.dao = new DAO<>(TipoNotaFiscal.class);
    }
    
    public void inserir(TipoNotaFiscal tipoNotaFiscal){
        dao.adiciona(tipoNotaFiscal);
    }
    
    public void alterar(TipoNotaFiscal tipoNotaFiscal){
        dao.atualiza(tipoNotaFiscal);
    }
    
    public List<TipoNotaFiscal> listar(){
        return dao.listaTodos();
    }
    
    public void remover(TipoNotaFiscal tipoNotaFiscal){
        dao.remove(tipoNotaFiscal);
    }
    
    public boolean jaExiste(TipoNotaFiscal tipoNotaFiscal) {
        List<TipoNotaFiscal> lista = this.listar();
        for (TipoNotaFiscal tnf : lista) 
            if(tnf.equals(tipoNotaFiscal))
                return true;
        return false;
    }

    public boolean existeDocumentoVinculado(TipoNotaFiscal tipoNotaFiscal) {
        return !(new DAO<>(Documento.class).consultar("NotaFiscal.buscaTipoNotaFiscal", tipoNotaFiscal).isEmpty());
    }
    
}
